<template>
	<view class="container">


		<view class="balance-info">
			<view>我的余额:</view>
			<view class="balance">${{ userInfo.banlace }}</view>
			<view>* 最低提现金额为：{{downAccount}}:</view>
			<view class="exchange" @click="onConsumeRecord">
				<text>提款记录</text>
				<text class="iconfont icon-more"></text>
			</view>
		</view>

		<view class="form">

			<view class="form-item">
				<text class="title">提现金额:</text>
				<view class="payouts">
					<text style="font-size: 50rpx;">￥</text>
					<input v-model="amount" type="number" placeholder="请输入提现金额" class="input" />
					<view class="payout" @click="withdrawAll">
						全部提现
					</view>
				</view>


			</view>


			<view class="recharge-btn">
				<u-checkbox-group @change="changeFn">
					<u-checkbox></u-checkbox>
				</u-checkbox-group>
				<!-- <checkbox v-model="agreementChecked" /> -->
				<text @click="show2=true">我已经同意提现协议</text>
				<view class="btn" @click="submitWithdrawal">
					提现
				</view>
			</view>
			<!-- <button @click="submitWithdrawal" class="submit-button" :disabled="!agreementChecked">提交提现申请</button> -->
		</view>
		
		<u-popup :show="show2" round="10" mode="center" @close="show2 =false" @open="open">
			<view style="margin: 20rpx;">
				<view class="title1" style="text-align: center;">
					提现入驻协议
				</view>
				<scroll-view style="height: 300px;" scroll-y="true" class="scroll-Y">
					<view v-html="textConten"> </view>
				</scroll-view>
			</view>
		</u-popup>
		
		
	</view>
</template>

<script>
	
	import {
		getAgreementData,
		payouts
	} from '@/config/api.js';
	export default {
		data() {
			const userInfo = uni.getStorageSync('userInfo');
			return {
				textConten: '',
				show2:false,
				isAgreed:false,
				userInfo,
				downAccount: '',
				balance: 500, // 用户余额
				amount: '', // 输入的提现金额
				agreementChecked: false, // 是否同意协议
			};
		},
		onLoad(){
			getAgreementData({
				id: 6,
				recharge_id: 1
			}).then(res => {
				this.textConten = res.data;
				this.downAccount = res.recharge;
			})
			
		},
		methods: {
			onConsumeRecord() {
				uni.navigateTo({
					url: '/pages/ConsumeRecord/ConsumeRecord?tx=1'
				})
			},
			changeFn(e) {
				this.isAgreed = !!e.length;
			
			},
			withdrawAll() {
				this.amount = this.balance.toString(); // 设置提现金额为余额
			},
			submitWithdrawal() {
				if (!this.amount || this.amount <= 0) {
					uni.showToast({
						title: '请填写有效的提现金额',
						icon: 'none',
					});
					return;
				}
				if (Number(this.amount) > Number(this.userInfo.banlace)) {
					uni.showToast({
						title: '余额不足',
						icon: 'none',
					});
					return;
				}
				if (Number(this.amount) < Number(this.downAccount)) {
					uni.showToast({
						title: '未达到提款要求！',
						icon: 'none',
					});
					return;
				}
				payouts({account: this.amount}).then(res => {
					uni.showToast({
						title: '提款已提交请耐心等待审核！',
						icon: 'success',
					});
				})
			
			},
			changeFn(e) {
				this.agreementChecked = true;
			},
		},
	};
</script>

<style scoped lang="scss">
	@import 'Payouts.scss';
</style>